<?php
include_once("./_common.php");
//include_once("$g4[path]/m/branch/adm_head.php");


$sql = "SELECT *
		FROM visit_record
		WHERE id = '$id'";
$rst = sql_query($sql);
//$view = mysql_fetch_assoc($rst2);
while($row = mysql_fetch_assoc($rst))
{
	$list[] = $row;
}


$sql2 = "SELECT y{$this_year}
		 FROM month_avg
		 WHERE store_num = '$branch'";
$rst2 = sql_query($sql2);
$view2 = mysql_fetch_assoc($rst2);


$this_year = date("Y");
$this_str = $view2["y".$this_year];
$vi_month = explode(",", $this_str);


$mnth1 = 0;
$mnth2 = 0;
$mnth3 = 0;
$mnth4 = 0;
$mnth5 = 0;
$mnth6 = 0;
$mnth7 = 0;
$mnth8 = 0;
$mnth9 = 0;
$mnth10 = 0;
$mnth11 = 0;
$mnth12 = 0;


//평균값 구하기
if ($vi_month['0'] != "")
{
	$mnth1 = $vi_month['0'];
}
if ($vi_month['1'] != "")
{
	$mnth2 = $vi_month['1'];
}
if ($vi_month['2'] != "")
{
	$mnth3 = $vi_month['2'];
}
if ($vi_month['3'] != "")
{
	$mnth4 = $vi_month['3'];
}
if ($vi_month['4'] != "")
{
	$mnth5 = $vi_month['4'];
}
if ($vi_month['5'] != "")
{
	$mnth6 = $vi_month['5'];
}
if ($vi_month['6'] != "")
{
	$mnth7 = $vi_month['6'];
}
if ($vi_month['7'] != "")
{
	$mnth8 = $vi_month['7'];
}
if ($vi_month['8'] != "")
{
	$mnth9 = $vi_month['8'];
}
if ($vi_month['9'] != "")
{
	$mnth10 = $vi_month['9'];
}
if ($vi_month['10'] != "")
{
	$mnth11 = $vi_month['10'];
}
if ($vi_month['11'] != "")
{
	$mnth12 = $vi_month['11'];
}

$sumMnth = (int)$mnth1 + (int)$mnth2 + (int)$mnth3 + (int)$mnth4 + (int)$mnth5 + (int)$mnth6 + (int)$mnth7 + (int)$mnth8 + (int)$mnth9 + (int)$mnth10 + (int)$mnth11 + (int)$mnth12;

$result = "";

if (count($list) == 1)
{
	$result = $list[0]['id']."<col>".$list[0]['vi_no']."<col>".$list[0]['vi_date']."<col>".$list[0]['vi_flag']."<col>".$list[0]['vi_name1']."<col>".$list[0]['vi_time']."<col>".$list[0]['vi_store']."<col>".$list[0]['vi_name2']."<col>".$list[0]['vi_count']."<col>".$list[0]['vi_avg']."<col>".$list[0]['vi_hall']."<col>".$list[0]['vi_sign']."<col>".$list[0]['vi_show']."<col>".$list[0]['vi_cash']."<col>".$list[0]['vi_uni']."<col>".$list[0]['vi_content']."<col>".$list[0]['vi_confirm']."<col>".$list[0]['vi_area']."<col>".$list[0]['vi_update_date']."<col>".$list[0]['vi_update_time']."<col>".$list[0]['j_data']."<col>".$list[0]['vi_file0']."<col>".$list[0]['vi_file1']."<col>".$list[0]['vi_sales']."<col>".$list[0]['vi_event']."<col>".$sumMnth."<col>END"."<row>";
}
else
{
	$result = "Database Error";
}

echo($result);

?>
